/**
 * SUNING APPLIANCE CHAINS.
 * Copyright (c) 2015-2015 All Rights Reserved.
 */
package com.suning.sawp.in.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

import com.suning.framework.web.exception.ErrorCodeMappingExceptionResolver;
import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.in.controller.MyGsonView;

/**
 * 系统异常处理
 *
 */

public class MyExceptionResolver extends ErrorCodeMappingExceptionResolver {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(MyExceptionResolver.class);

	public static final String RET_FALG = "retFlag";
	public static final String ERROR_CODE = "errorCode";
	public static final String ERROR_MESSAGE = "errorMessage";

	public static final String FAIL = "0";

	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		LOGGER.error("doResolveException", ex);

		ModelAndView modelAndView = new ModelAndView();

		MyGsonView gsonView = new MyGsonView();
		gsonView.addStaticAttribute(RET_FALG, FAIL);
		gsonView.addStaticAttribute(ERROR_CODE,
				ErrorCodeConstants.ERR_0002);
		gsonView.addStaticAttribute(ERROR_MESSAGE, ex.getMessage());

		// 返回json报文
		modelAndView.setView(gsonView);
		return modelAndView;
	}

}
